package com.ruoyi.utils;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/h5")
public class treeselectUtils {

    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private SysDeptMapper sysDeptMapper;

    /**
     * 获取部门下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(SysDept dept)
    {
        List<SysDept> s = new ArrayList<>();

        List<SysDept> depts = sysDeptMapper.selectDeptList(dept);
        List<SysDept> sysDepts = deptService.buildDeptTree(depts);
        List<SysDept> children1 = sysDepts.get(0).getChildren();
        for(SysDept d:children1){
            List<SysDept> children = d.getChildren();
            for(SysDept sd:children){
                SysDept de = new SysDept();
                de.setDeptId(sd.getDeptId());
                de.setDeptName(d.getDeptName() + "----" + sd.getDeptName());
                s.add(de);
            }
        }
        return AjaxResult.success(s);
    }

}
